# -*- coding;utf-8 -*-
"""
File name : Pdf2Word_duhui_step1.PY
Program IDE : PyCharm
Create file time: 2023/9/9 11:37
File Create By Author : 朱清闯
"""

# !/usr/bin/env python
# -*- coding: utf-8 -*-

import requests


# 向度慧第三方服务器提交pdf在本服务器的url，并返回token
def pdf2word_step1(file_url):
    url = 'http://pdf2doc.api.bdymkt.com/v1/convert'
    params = {}
    params['url'] = file_url
    params['type'] = 'docx'
    params['ocr'] = ''
    params['language'] = ''
    params['outfilename'] = ''
    params['callbackurl'] = ''
    params['excelonesheet'] = ''
    params['password'] = ''
    params['pageindexes'] = ''
    params['wordnoimage'] = ''

    headers = {
        'Content-Type': 'application/json;charset=UTF-8',
        'X-Bce-Signature': 'AppCode/3fd3f916d812488e9da5b9daeba9986d'
    }
    r = requests.request("GET", url, params=params, headers=headers)
    return r.content


# 带上token，去获取转换后docx的结果
def pdf2word_step2(token):
    url = 'https://api.duhuitech.com/q'
    params = {}
    params['token'] = token
    headers = {
        'Content-Type': 'application/json;charset=UTF-8',
    }
    r = requests.request("GET", url, params=params, headers=headers)
    return r.content